<%@page import="com.neiquan.backstage.user.UserService"%>
<%@page import="com.neiquan.backstage.pub.bsc.dao.po.User"%>
<%@page import="com.neiquan.backstage.common.util.Sessions"%>
<%@page import="com.neiquan.backstage.pub.bsc.dao.po.AdminUser"%>
<%@page import="org.hibernate.Session"%>
<%@page import="com.neiquan.backstage.convenience_service.ConvenienceServiceService"%>
<%@page import="com.neiquan.backstage.pub.bsc.dao.po.ConvenienceService"%>
<%@page import="com.neiquan.backstage.pub.bsc.dao.po.Event"%>
<%@page import="java.util.List"%>
<%@page import="com.neiquan.backstage.common.CommonService"%>
<%@page import="com.neiquan.backstage.common.util.SpringContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
ApplicationContext appCtx = SpringContextUtils.getApplicationContext();
UserService userService = appCtx.getBean(UserService.class);
User loginedUser = (User) Sessions.getLoginedUser(session);
int memberId=loginedUser.getMemberId(); 
String entrepreneurUniqueId=loginedUser.getEntrepreneurUniqueId();
List<User>  users= userService.queryEmplByStatus(memberId,entrepreneurUniqueId);
pageContext.setAttribute("users", users);
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="UTF-8">
	<title>员工管理</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1.0" />
	<meta name="apple-mobile-web-app-capable" content="yes" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<link rel="stylesheet" href="css/base.css" />
	<link rel="stylesheet" href="css/main.css" />
</head>
<body bgcolor="#f0f0f0">
		<section class="common_bg manager_wrap">
			<ul>
				<li class="manager_title">
					<span>姓名</span>
					<span>手机号</span>
					<span>操作</span>
				</li>
				<%for(User u:users){%>
					<li id="li<%=u.getUserId()%>" class="manager_title manager_list record_cont">
					<span><%=u.getName() %></span>
					<span><%=u.getPhone() %></span>
					<%if(u.getStatus()==0){ %>
					<span>
						<time class="manager-ok" onclick="pass(<%=u.getUserId()%>)">通过</time>
						<time class="manager-no reject" onclick="reject(<%=u.getUserId()%>)">驳回</time>
					</span>
					<%} %>
					<%if(u.getStatus()==1){ %>
					<span>
						<time class="manager-ok" onclick="idet(<%=u.getUserId()%>)">编辑</time>
						<time class="manager-no delete" onclick="delet(<%=u.getUserId()%>)">删除</time>
					</span>
					<%} %>
					<%if(u.getStatus()==2){ %>
					<span>
						<time class="manager-ok" >已被驳回</time>
						<time class="manager-no delete" onclick="delet(<%=u.getUserId()%>)">删除</time>
					</span>
					<%} %>
				</li>
				<%} %>
			</ul>
			<section class="manager-popup-wrap">
				<section class="manager-popup prompt">
					<p class="prompt-title">提示</p>
					<section class="prompt-cont">
						<p class="ask tc">删除后不可恢复确定要删除吗？</p>
						<p class="pd popup-btn">
							<button class="ask-btn ask-ok btn">确定</button>
							<button class="ask-btn ask-del btn">取消</button>
						</p>
					</section>
				</section>
				<section class="manager-popup rebut">
					<p class="prompt-title">驳回</p>
					<section class="prompt-cont">
						<textarea name="" rows="6" cols="40">请输入驳回原因...</textarea>
						<p class="popup-btn">
							<button class="ask-btn ask-ok btn">确定</button>
							<button class="ask-btn ask-del btn">取消</button>
						</p>
					</section>
				</section>
			</section>
		</section>
</body>
		<script src="js/jquery.min.js"></script>
		<script src="js/main.js"></script>
		<script src="js/responsive.js"></script>
		<script type="text/javascript">
		//删除
		jQuery('.manager-popup-wrap').hide();
		function delet(userId){
			var jQuerythisElement = jQuery(this);
			jQuery('.manager-popup-wrap').show().children('.prompt').show().next().hide().prev().children('.prompt-cont').children('.popup-btn').children('.ask-btn').click(function(){
				jQuery('.manager-popup-wrap').hide();
				if(jQuery(this).html() == "确定"){
					var url="api/user/remove";
					var req={
						"id":userId
					}
					jQuery.post(url,req,function(data){
						if (data.code != 0) {
							alert(data.errorMessage);
							return;
						}
						window.location.href = "employeemanager.jsp?r=" + new Date();
					}); 
						jQuery('#li'+userId).remove();
				}
			});
		}; 
		//通过
		function pass(userId){
			var jQuerythisElement = jQuery(this);
			var url="api/user/pass";
			var req={
					"id":userId
				}
			jQuery.post(url,req,function(data){
				if (data.code != 0) {
					alert(data.errorMessage);
					return;
					} 
				window.location.href = "employeemanager.jsp?r=" + new Date();
				});
		};
		//编辑
		function idet(userId){
			window.location.href = "employeedetail.jsp?id=" + userId;
		} ;
		//驳回操作
		jQuery('textarea').focus(function(){
			jQuery(this).html("");
		})
		function reject(userId){
			jQuery('.manager-popup-wrap').show().children('.rebut').show().prev().hide().next().children('.prompt-cont').children('.popup-btn').children('.ask-btn').click(function(){
				jQuery('.manager-popup-wrap').hide();
				if(jQuery(this).html() == "确定"){
					var url="api/user/reject";
					var remark=jQuery('textarea').val();
					var req={
						"id":userId,
						"remark":remark
					}
				 	jQuery.post(url,req,function(data){
						if (data.code != 0) {
							alert(data.errorMessage);
							return;
						} 
						window.location.href = "employeemanager.jsp?r=" + new Date();
					}); 
				}
			});
		} 
		</script>
</html>
